//
//  Date+Extesions.swift
//  GlassDatabase
//
//  Created by 李然 on 2023/5/26.
//

import Foundation
import SwiftDate

public extension Date {
    
    /// 最近7天日期范围
    var curRecentSevenDayRange: (start: Date, end: Date) {
        return (start: (self - 6.days).dateAtStartOf(.day), end: self.dateAtEndOf(.day))
    }
    
    /// 本周日期范围
    var curWeekRange: (start: Date, end: Date) {
        return (start: self.dateAtStartOf(.weekOfYear), end: self.dateAtEndOf(.weekOfYear))
    }
    
    /// 本月日期范围
    var curMonthRange: (start: Date, end: Date) {
        return (start: self.dateAtStartOf(.month), end: self.dateAtEndOf(.month))
    }
    
    /// 本年日期范围
    var curYearRange: (start: Date, end: Date) {
        var end = min(self.dateAtEndOf(.year), Date())
        return (start: self.dateAtStartOf(.year), end: end)
    }
}
